﻿Imports System
Imports System.Workflow.ComponentModel.Compiler

Namespace System.Workflow.Activities
    Friend NotInheritable Class IfElseBranchValidator
        Inherits CompositeActivityValidator
        ' Methods
        Public Overrides Function Validate(ByVal manager As ValidationManager, ByVal obj As Object) As ValidationErrorCollection
            Dim errors As ValidationErrorCollection = MyBase.Validate(manager, obj)
            Dim activity As IfElseBranchActivity = [TryCast](obj,IfElseBranchActivity)
            If (activity Is Nothing) Then
                Throw New ArgumentException(SR.GetString("Error_UnexpectedArgumentType", New Object() { GetType(IfElseBranchActivity).FullName }), "obj")
            End If
            Dim parent As IfElseActivity = [TryCast](activity.Parent,IfElseActivity)
            If (parent Is Nothing) Then
                errors.Add(New ValidationError(SR.GetString("Error_ConditionalBranchParentNotConditional"), &H50E))
            End If
            If (((((parent Is Nothing) OrElse (parent.EnabledActivities.Count <= 1)) OrElse (Not parent.EnabledActivities.Item((parent.EnabledActivities.Count - 1)) Is activity)) OrElse (Not activity.Condition Is Nothing)) AndAlso (activity.Condition Is Nothing)) Then
                errors.Add(ValidationError.GetNotSetValidationError("Condition"))
            End If
            Return errors
        End Function

    End Class
End Namespace

